/*
 * [程序名称] Weather auto sender
 * [参考资料] http://code.google.com/p/auto-weather-sender/ 
 * [开源协议] Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.joe.weather.tool;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.joe.weather.R;

public class PreferenceUtil
{
	private static String[] name_keyArray;
	private static String[] name_valueArray;
	private static String[] city_keyArray;
	private static String[] city_valueArray;
	
	private Context context;

	public PreferenceUtil(Context context)
	{
		super();
		this.context = context;
		
		name_keyArray = context.getResources().getStringArray(R.array.name_key_list_preference);
		name_valueArray = context.getResources().getStringArray(R.array.name_value_list_preference);
		
		city_keyArray = context.getResources().getStringArray(R.array.city_key_list_preference);
		city_valueArray = context.getResources().getStringArray(R.array.city_value_list_preference);
	}
	
	public String getCurrentCallName()
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		String callCode = sp.getString("callName", "1");
		if(name_valueArray != null && name_valueArray.length != 0)
		{
			for(int i=0; i<name_valueArray.length; i++)
			{
				if(callCode.equals(name_valueArray[i]))
				{
					return name_keyArray[i];
				}
			}
		}
		
		return "pp";
	}
	
	public String getCurrentCityName(String cityCode)
	{
		if(city_valueArray != null && city_valueArray.length != 0)
		{
			for(int i=0; i<city_valueArray.length; i++)
			{
				if(cityCode.equals(city_valueArray[i]))
				{
					return city_keyArray[i];
				}
			}
		}
		
		return "广州";
	}
}
